package game.objects.texts 
{
	import net.flashpunk.Entity;
	import net.flashpunk.graphics.Image;
	import net.flashpunk.graphics.Text;
	import net.flashpunk.Tween;
	import net.flashpunk.tweens.misc.NumTween;
	import net.flashpunk.tweens.motion.LinearMotion;
	/**
	 * ...
	 * @author rnk
	 */
	public class FloatingText extends Entity
	{
		private var tween:LinearMotion;
		
		public function FloatingText(x:Number,y:Number,txt:String) 
		{
			this.x = x;
			this.y = y;
			var text:Text = new Text(txt);
			graphic = text;
			graphic.x -= (text.width) / 2;
			graphic.y -= (text.height);
			tween = new LinearMotion(OnTweenComplete, Tween.ONESHOT);
			addTween(tween);
			tween.setMotion(x, y, x, y - 50, 15,Ease.quadOut);
			tween.start();
			
		}
		
		private function OnTweenComplete():void 
		{
			var waitTween:NumTween = new NumTween(OnNumTweenComplete, Tween.ONESHOT);
			addTween(waitTween);
			waitTween.tween(0, 1.0, 15);
			waitTween.start();
		}
		
		private function OnNumTweenComplete():void 
		{
			world.remove(this);
		}
		
		override public function update():void 
		{
			super.update();
			x = tween.x;
			y = tween.y;
		}
		
	}

}